package net.jiastudy.biz.sys.service;

import java.util.List;
import java.util.Map;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.validation.annotation.Validated;

import net.jiastudy.biz.sys.entity.Dict;

public interface DictService {

	public Dict getDictById(Long id);

	@Caching(evict = { @CacheEvict(value = "dict", key = "'groupCode:'+#result.groupCode+':dictKey:'+#result.dictKey"),
			@CacheEvict(value = "dict", key = "'groupCode:'+#result.groupCode"),
			@CacheEvict(value = "dict", allEntries = true), @CacheEvict(value = "dictkv", allEntries = true) })
	public Dict createDict(Dict dict);

	@Caching(evict = { @CacheEvict(value = "dict", key = "'groupCode:'+#result.groupCode+':dictKey:'+#result.dictKey"),
			@CacheEvict(value = "dict", key = "'groupCode:'+#result.groupCode"),
			@CacheEvict(value = "dict", allEntries = true), @CacheEvict(value = "dictkv", allEntries = true) })
	public Dict updateDict(Dict dict);

	@Caching(evict = { @CacheEvict(value = "dict", key = "'groupCode:'+#groupCode+':dictKey:'+#dictKey"),
			@CacheEvict(value = "dict", key = "'groupCode:'+#groupCode"),
			@CacheEvict(value = "dict", allEntries = true), @CacheEvict(value = "dictkv", allEntries = true) })
	public boolean deleteDict(String groupCode, String dictKey);

	@Cacheable(value = "dict", key = "'groupCode:'+#groupCode+':dictKey:'+#dictKey", unless = "#result == null")
	public Dict getDictByGroupCodeAndKey(String groupCode, String dictKey);

	@Cacheable(value = "dict", key = "'groupCode:'+#groupCode", unless = "#result == null")
	public List<Dict> findDictsByGroupCode(String groupCode);

	@Cacheable(value = "dict", key = "'groupCode:'+#groupCode+':isAsc:'+#isAsc", unless = "#result == null")
	public List<Dict> findDictsByGroupCode(String groupCode, boolean isAsc);

	public boolean checkDictKeyExists(@Validated String groupCode, @Validated String dictKey, Long currentDictId);

	public Integer getNextSeqByGroupCode(String groupCode);

	@Cacheable(value = "dictkv", key = "'groupCode:'+#groupCode+':isAsc:'+#isAsc", unless = "#result == null")
	public List<Map<String, String>> findDictKv(String groupCode, boolean isAsc);
}
